package routers

import (
	beego "github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/server/web/filter/cors"
	"passwordBook/controller"
)

func init() {
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		AllowCredentials: true,
	}))

	beego.Router("/pwbook/create", &controller.PwBookController{}, "post:Create")
	beego.Router("/pwbook/list", &controller.PwBookController{}, "post:List")
	beego.Router("/pwbook/delete/:id", &controller.PwBookController{}, "post:Delete")
	beego.Router("/pwbook/edit", &controller.PwBookController{}, "post:Edit")

	beego.Router("/pwitem/create", &controller.PwController{}, "post:Create")
	beego.Router("/pwitem/update", &controller.PwController{}, "post:Update")
	beego.Router("/pwitem/delete/:id", &controller.PwController{}, "post:Delete")
	beego.Router("/pwitem/list", &controller.PwController{}, "post:List")
	beego.Router("/pwitem/showPwd", &controller.PwController{}, "post:ShowPwd")

	beego.Router("/config/list", &controller.ConfigController{}, "post:List")
	beego.Router("/config/edit", &controller.ConfigController{}, "post:Edit")
}
